/**
* Copyright (C) 2018-2022
* All rights reserved, Designed By www.yixiang.co
* 注意：
* 本软件为www.yixiang.co开发研制，未经购买不得使用
* 购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
* 一经发现盗用、分享等行为，将追究法律责任，后果自负
*/
package co.yixiang.modules.tanzer.service.impl;

import co.yixiang.modules.tanzer.domain.Manicurist;
import co.yixiang.common.service.impl.BaseServiceImpl;
import lombok.AllArgsConstructor;
import co.yixiang.dozer.service.IGenerator;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import co.yixiang.common.utils.QueryHelpPlus;
import co.yixiang.utils.ValidationUtil;
import co.yixiang.utils.FileUtil;
import co.yixiang.modules.tanzer.service.ManicuristService;
import co.yixiang.modules.tanzer.service.dto.ManicuristDto;
import co.yixiang.modules.tanzer.service.dto.ManicuristQueryCriteria;
import co.yixiang.modules.tanzer.service.mapper.ManicuristMapper;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
// 默认不使用缓存
//import org.springframework.cache.annotation.CacheConfig;
//import org.springframework.cache.annotation.CacheEvict;
//import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import java.util.List;
import java.util.Map;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import co.yixiang.domain.PageResult;
/**
* @author hupeng
* @date 2024-08-03
*/
@Service
@AllArgsConstructor
//@CacheConfig(cacheNames = "manicurist")
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
public class ManicuristServiceImpl extends BaseServiceImpl<ManicuristMapper, Manicurist> implements ManicuristService {

    private final IGenerator generator;

    @Override
    //@Cacheable
    public PageResult<ManicuristDto> queryAll(ManicuristQueryCriteria criteria, Pageable pageable) {
        getPage(pageable);
        PageInfo<Manicurist> page = new PageInfo<>(queryAll(criteria));
        return generator.convertPageInfo(page,ManicuristDto.class);
    }


    @Override
    //@Cacheable
    public List<Manicurist> queryAll(ManicuristQueryCriteria criteria){
        return baseMapper.selectList(QueryHelpPlus.getPredicate(Manicurist.class, criteria));
    }


    @Override
    public void download(List<ManicuristDto> all, HttpServletResponse response) throws IOException {
        List<Map<String, Object>> list = new ArrayList<>();
        for (ManicuristDto manicurist : all) {
            Map<String,Object> map = new LinkedHashMap<>();
            map.put("美甲师名称", manicurist.getManicuristName());
            map.put("美甲师编码", manicurist.getManicuristCode());
            map.put("美甲师电话", manicurist.getManicuristTel());
            map.put("美甲师微信", manicurist.getManicuristWechat());
            map.put("押金", manicurist.getManicuristDeposit());
            map.put("地址", manicurist.getManicuristAddr());
            map.put("状态", manicurist.getEnabledFlag());
            map.put("备注说明", manicurist.getRemark());
            map.put("创建日期", manicurist.getCreateTime());
            map.put(" updateTime",  manicurist.getUpdateTime());
            map.put(" isDel",  manicurist.getIsDel());
            map.put(" attribute1",  manicurist.getAttribute1());
            map.put(" attribute2",  manicurist.getAttribute2());
            map.put(" attribute3",  manicurist.getAttribute3());
            map.put(" attribute4",  manicurist.getAttribute4());
            map.put(" attribute5",  manicurist.getAttribute5());
            list.add(map);
        }
        FileUtil.downloadExcel(list, response);
    }
}
